package com.lengmou.service.impl;

import com.lengmou.dao.BookMarkDao;
import com.lengmou.entity.BookMark;
import com.lengmou.service.BookMarkService;
import com.lengmou.util.TimeTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
@Service("BookMarkService")
public class BookMarkServiceImpl implements BookMarkService {
    @Resource
    private BookMarkDao bmd;
    @Override
    public List<BookMark> getAll() {
        return bmd.querysAll();
    }

    @Override
    public List<BookMark> getUsersBookMark(int userid) {
        return bmd.querysByUserId(userid);
    }

    @Override
    public BookMark getBookMarkById(String id) {
        return bmd.queryById(id);
    }

    @Override
    public int addBookMark(BookMark bookMark) {
//        初始化参数
        bookMark.setId(UUID.randomUUID().toString());
        bookMark.setCreatetime(TimeTool.time());
        return bmd.addBookMark(bookMark);
    }

    @Override
    public int setBookMarkUserid(BookMark bookMark) {
        BookMark bookMarkById = getBookMarkById(bookMark.getId());
        if(bookMarkById!=null){
            bookMarkById.setUserid(bookMark.getUserid());
            return bmd.updateBookMark(bookMarkById);
        }
        return -1;
    }

    @Override
    public int setBookMarkGoodsid(BookMark bookMark) {
        BookMark bookMarkById = getBookMarkById(bookMark.getId());
        if(bookMarkById!=null){
            bookMarkById.setGoodsid(bookMark.getGoodsid());
            return bmd.updateBookMark(bookMarkById);
        }
        return -1;
    }

    @Override
    public int setBookMarkTime(BookMark bookMark) {
        BookMark bookMarkById = getBookMarkById(bookMark.getId());
        if(bookMarkById!=null){
            bookMarkById.setCreatetime(bookMark.getCreatetime());
            return bmd.updateBookMark(bookMarkById);
        }
        return -1;
    }

    @Override
    public int deleteBookMark(String id) {

        BookMark bookMarkById = getBookMarkById(id);
        if(bookMarkById!=null){
            return bmd.deleteBookMark(id);
        }
        return -1;
    }
}
